<?php

namespace App\Http\Controller\Admin;

use App\Exception\HttpException;
use App\Model\Logic\ConfigLogic;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Http\Message\Request;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\Http\Server\Annotation\Mapping\RequestMethod;

/**
 * @Controller(prefix="/admin")
 * Class ManagerController
 * @package App\Http\Controller\Admin
 */
class ConfigController
{
    /**
     * @Inject()
     * @var ConfigLogic
     */
    private $configLogic;

    /**
     * @RequestMapping(route="config", method={RequestMethod::GET})
     * @return \Swoft\Http\Message\Response
     * @throws \Throwable
     */
    public function index(){
        $config = $this->configLogic->getConfig();
        return view("admin/config/config", ["config"=>$config]);
    }

    /**
     * @RequestMapping(route="saveconfig", method={RequestMethod::POST})
     * @param Request $request
     * @throws HttpException
     */
    public function saveConfig(Request $request){
        if(!$request->isAjax()){
            throw new HttpException('请求异常');
        }
        //接收数据
        $data= $request->post();
        //提交逻辑层处理
        $this->configLogic->saveData($data);
    }
}
